<template>
    <div style="margin-top: 30px;margin-left: 50px">
        <el-row :gutter="10" style="margin-bottom: 40px; ">

          <el-col :span="6">
            <el-card style="color: #409EFF">
              <div >客户总数</div>
              <div style="padding: 10px 0; text-align: center; font-weight: bold;">
                100
              </div>
            </el-card>
          </el-col>

          <el-col :span="6">
            <el-card style="color: #67C23A">
              <div >流水额度</div>
              <div style="padding: 10px 0; text-align: center; font-weight: bold;">
                ￥1000000
              </div>
            </el-card>
          </el-col>

          <el-col :span="6">
            <el-card  style="color: #E6A23C">
              <div >收益总额</div>
              <div style="padding: 10px 0; text-align: center; font-weight: bold;">
                300000
              </div>
            </el-card>
          </el-col>

          <el-col :span="6">
            <el-card style="color: #909399">
              <div >零部件库存</div>
              <div style="padding: 10px 0; text-align: center; font-weight: bold;">
                2000
              </div>
            </el-card>
          </el-col>

        </el-row>
      <el-row>
        <el-col :span="12">
          <div id="main" style="width: 600px; height: 600px"></div>
        </el-col>
        <el-col :span="12">
          <div id="pie"  style="width: 600px; height: 600px; margin-top: 40px"></div>
        </el-col>
      </el-row>
    </div>
</template>

<script>

import * as echarts from 'echarts'


export default {
  name: "Home",
  data(){
    return{

    }
  },
  mounted() {//页面元素渲染之后再触发

    //折线柱状图
    var option = {
      title: {
        text: '各季度客户汇总',
        subtext: '趋势图',
        left: 'center'
      },
      xAxis: {
        type: 'category',
        data: ["春","夏","秋","冬",]
      },
      yAxis: {
        type: 'value',
      },
      series: [
        {
          data: [],
          type: 'line',
        },
        {
          data: [],
          type: 'bar',
        }
      ]
    };

    //饼图
    var  pieOption = {
      title: {
        text: '各季度客户统计',
        subtext: '比例图',
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        orient: 'vertical',
        left: 'left'
      },
      series: [
        {
          type: 'pie',
          radius: '70%',

          label:{            //饼图图形上的文本标签
            normal:{
              show:true,
              position:'inner', //标签的位置
              textStyle : {
                fontWeight : 300 ,
                fontSize : 18
                 ,    //文字的字体大小
                color: "#fff"
              },
              formatter:'{d}%'
            }
          },

          data: [  //填写数据库数据

          ],
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        }
      ]
    };


    var chartDom = document.getElementById('main');//获取id为“main”的标签
    var myChart = echarts.init(chartDom);//初始化

    var pieDom = document.getElementById('pie');//获取id为“main”的标签
    var pieChart = echarts.init(pieDom);//初始化


    this.request.get("/echarts/members").then(res =>{
      //填空
      // option.xAxis.data = res.data.x;
      option.series[0].data = res.da·ta
      option.series[1].data = res.data
      //数据准备完毕之后再set
      myChart.setOption(option);


      pieOption.series[0].data = [
        {name: "第一季度", value: res.data[0]},
        {name: "第二季度", value: res.data[1]},
        {name: "第三季度", value: res.data[2]},
        {name: "第四季度", value: res.data[3]},
      ]
      pieChart.setOption(pieOption)

    })


    pieChart.setOption(pieOption)

  }
}
</script>

<style scoped>

</style>